class Solution(object):
    def validUtf8(self, data):
        """
        :type data: List[int]
        :rtype: bool
        """
        tail = 0
        for ch in data:
            if tail!=0:
                if ch&0b11000000==0b10000000: tail-=1
                else: return False
            else:
                if 0b0<=ch<=0b01111111:
                    tail = 0
                elif ch&0b11100000==0b11000000: 
                    tail = 1
                elif ch&0b11110000==0b11100000: 
                    tail = 2
                elif ch&0b11111000==0b11110000:
                    tail = 3
                else: 
                    return False
        return tail==0

print(Solution().validUtf8([237]))
